package com.ebupt.migu.music.push.controller;

import com.ebupt.migu.music.push.service.PushTaskService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.text.ParseException;

/**
 * Created by Intellij IDEA. User: liuyangyang@cd.ebupt.com Date: 2019/10/31
 */
@Slf4j
@Component
@EnableScheduling
public class PushTask {

    @Resource
    private PushTaskService pushTaskService;

    /**
     * PUSH策略： 立即PUSH 每分钟执行一次定时任务
     */
    @Scheduled(initialDelay = 1000, fixedDelay = 1000 * 60)
    public void pushNow() {
        log.info("PUSH策略【立即PUSH】定时任务启动");
        pushTaskService.pushNow();
        log.info("PUSH策略【立即PUSH】定时任务结束");
    }

    /**
     * PUSH策略： 单次PUSH 每五分钟执行一次定时任务
     */
    @Scheduled(initialDelay = 2000, fixedDelay = 1000 * 60)
    public void pushOnce() {
        log.info("PUSH策略【单次PUSH】定时任务启动");
        pushTaskService.pushOnce();
        log.info("PUSH策略【单次PUSH】定时任务结束");
    }

    /**
     * PUSH策略： 策略周期内重复执行PUSH 每五分钟执行一次定时任务
     */
    @Scheduled(initialDelay = 3000, fixedDelay = 1000 * 60 * 5)
    public void pushLoop() throws ParseException {
        log.info("PUSH策略【循环PUSH】定时任务启动");
        pushTaskService.pushLoop();
        log.info("PUSH策略【循环PUSH】定时任务结束");
    }

    /**
     * PUSH策略： 策略周期内间隔PUSH 每五分钟执行一次定时任务
     */
    @Scheduled(initialDelay = 5000, fixedDelay = 1000 * 60 * 5)
    public void pushInterval() throws ParseException {
        log.info("PUSH策略【间隔PUSH】定时任务启动");
        pushTaskService.pushInterval();
        log.info("PUSH策略【间隔PUSH】定时任务结束");
    }

    /**
     * PUSH策略： 策略周期内间隔PUSH 每五分钟执行一次定时任务
     */
    @Scheduled(initialDelay = 5000, fixedDelay = 1000 * 60 * 5)
    public void cid() throws ParseException {
        pushTaskService.cid();
    }

}
